home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS01.ADF
/
C
/
FixDate.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-01-09
|
8KB
|
326 lines
/*
* FIXDATE.C Version 0.0 December 12, 1985
* Copyright (c) 1985 Lee B. Grey, Atlanta, GA
*
* Permission is hereby granted to distribute FIXDATE freely, as long as
* no money is exchanged. It is in the public domain. No copies should
* be distributed without these comments or the credits.
*
* Written by Lee B. Grey
* 250 Bruton Way
* Atlanta, GA 30342
* (404) 851-9103
*
* FIXDATE works in the same manner as TREE, and they should be
* distributed together. FIXDATE is an ad hoc fix to a weird Amiga
* "virus." Due to some oddities in the way the Amiga's DATE command
* works and the way the Amiga checks dates on disks, many disks now
* have corrupted dates, which are virtually impossible to get rid of
* manually. Before you know it, your Amiga is in the 650th century.
* And Amigas do not work well that far in the future.
*
* FIXDATE checks every file and every directory on the specified disk,
* and corrects any dates which are not within the user's specified
* limits.
*
* Like TREE, FIXDATE is sloppy, uncommented, and not something I am eager
* to have people associate with my talents. However, it works, and it is
* needed. In addition to the updates I would like to make to TREE, FIXDATE
* could stand some specific improvements of its own:
*
* @ FIXDATE should accept a date, rather than the number of days as an
* integer. Of course, to avoid the problems with DATE, FIXDATE
* should receive a four-digit year, not a two-digit year.
*
* @ FIXDATE will probably need to work on hard-disks and other floppies.
* It currently only knows about df0: and df1:.
*
* @ FIXDATE should fix the system date, as well. At the moment, you can
* fix all of the dates on a disk and then promptly screw it up all
* over again, since the system date was not reset. To avoid this,
* after fixing the dates on a disk, that disk should be removed.
* Another alternative is to reset the machine after both disks have
* been FIXDATEd.
*
*/
#include <exec/types.h>
#include <exec/io.h>
#include <devices/trackdisk.h>
#define TD_READ CMD_READ
#define TD_WRITE CMD_WRITE
#define BLOCKSIZE TD_SECTOR
#define FL_SIZE sizeof(FileList)
typedef struct FileListStruct{
LONG block;
struct FileListStruct *next;
} FileList;
LONG LastLegal,ChangeTo;
char *malloc();
BYTE diskbuffer[BLOCKSIZE];
struct Port *diskport;
struct IOStdReq *diskreq;
FileList *Top,*Bot;
instruct()
{
printf("\n\nUsage: FIXDATE <drive> <last-legal-date> <set-bad-dates-to>\n\n");
printf(" Drive: ( df0: | df1: )\n");
printf(" Last legal date: Any date later than this date will be fixed\n");
printf(" Set bad dates to: Any date that is fixed will be set to this date\n");
printf("\n These dates must be entered as an integer\n");
printf(" which is the number of days since 01-JAN-78.\n");
printf("\n As a reference, 10-DEC-1985 was day 2900.\n\n");
exit(1);
}
main(argc,argv)
int argc;
char **argv;
{
SHORT error;
LONG drivenum,atol();
extern struct Port *CreatePort();
extern struct IOStdReq *CreateStdIO();
FileList *tmp;
if(argc != 4)
instruct();
else
printf("\n FIXDATE Version 0.0 Copyright 1985 Lee B. Grey\n\n");
if(!strcmp(argv[1],"df0:"))
drivenum = 0L;
else
if(!strcmp(argv[1],"df1:"))
drivenum = 1L;
else
instruct();
LastLegal = atol(argv[2]);
ChangeTo = atol(argv[3]);
diskport = CreatePort(0,0);
diskreq = CreateStdIO(diskport);
error = OpenDevice(TD_NAME,drivenum,diskreq,0);
if(error){
printf("Error opening device.\n\n");
endtree();
}
Bot = Top = (FileList *)malloc(FL_SIZE);
if(Bot == NULL){
printf("No memory left.\n\n");
endtree();
}
Top->block = 880;
Top->next = NULL;
while(Top != NULL){
ReadBlock(Top->block);
if(diskreq->io_Error != 0){
printf("Error in main after ReadBlock.\n\n");
endtree();
}
printf("\n\nDirectory %s",&diskbuffer[433]);
FixDate(Top->block);
ScanHash();
tmp = Top;
Top = Top->next;
if(free( (char *)tmp ) != 0){
printf("Error in freeing memory.\n\n");
endtree();
}
ShowFiles();
}
endtree();
}
FixChkSum()
{
LONG *data,tot;
int i;
data = &diskbuffer[20];
tot = *data = 0L;
data = &diskbuffer[0];
for(i=0;i<128;i++)
tot = tot + *(data++);
data = &diskbuffer[20];
*data = ~tot + 1L;
}
FixDate(blk)
LONG blk;
{
LONG *date1,*date2,*date3;
date1 = &diskbuffer[420];
date2 = &diskbuffer[472];
date3 = &diskbuffer[484];
if(*date1 > LastLegal ||
(blk == 880 && *date2 > LastLegal) ||
(blk == 880 && *date3 > LastLegal) ){
if(*date1 > LastLegal)
*date1 = ChangeTo;
if(blk == 880 && *date2 > LastLegal)
*date2 = ChangeTo;
if(blk == 880 && *date3 > LastLegal)
*date3 = ChangeTo;
FixChkSum();
WriteBlock(blk);
printf(" date set to %ld\n",ChangeTo);
}else
printf("\n");
}
ShowFiles()
{
FileList *use,*prev,*tmp;
LONG *diskdata;
use = Top;
prev = Top = Bot = NULL;
while(use != NULL){
ReadBlock(use->block);
if(diskreq->io_Error != 0){
printf("I/O error in ShowFiles.\n");
endtree();
}
diskdata = &diskbuffer[0];
if(*diskdata != 2L){
printf("Weird block read.\n\n");
use = use->next;
continue;
}
diskdata = &diskbuffer[496];
if(*diskdata != 0L){
tmp = (FileList *)malloc(FL_SIZE);
if(tmp == NULL){
printf("HASHCHAIN: No memory left.\n\n");
endtree();
}
tmp->block = *diskdata;
tmp->next = use->next;
use->next = tmp;
}
diskdata = &diskbuffer[508];
if(*diskdata == 2L)
if(Top == NULL){
Bot = prev = Top = use;
use = use->next;
continue;
}else{
Bot = prev = use;
use = use->next;
continue;
}
if(*diskdata == -3L){
printf(" %s",&diskbuffer[433]);
FixDate(use->block);
if(prev == NULL){
tmp = use;
use = use->next;
if(free( (char *)tmp ) != 0){
printf("SHOWFILES: Error in deallocation of memory.\n\n");
endtree();
}
continue;
}else{
tmp = use;
use = use->next;
prev->next = use;
if(free( (char *)tmp ) != 0){
printf("SHOWFILES: Error in deallocation of memory.\n\n");
endtree();
}
continue;
}
}
printf("Unrecognized code = %ld block = %ld\n\n",
*diskdata,use->block);
prev = use;
use = use->next;
}
}
ScanHash()
{
SHORT i;
LONG *data;
FileList *new;
for(data = &diskbuffer[24],i=6;i<78;i++,data++){
if(*data == 0L)
continue;
new = (FileList *)malloc(FL_SIZE);
if(new == NULL){
printf("SCANHASH: No memory left.\n\n");
endtree();
}
new->block = *data;
new->next = NULL;
Bot->next = new;
Bot = new;
}
}
WriteBlock(blk)
LONG blk;
{
diskreq->io_Length = BLOCKSIZE;
diskreq->io_Data = diskbuffer;
diskreq->io_Command = TD_WRITE;
diskreq->io_Offset = blk*512;
DoIO(diskreq);
if(diskreq->io_Error != 0){
printf("Error in write.\n\n");
endtree();
}
}
ReadBlock(blk)
LONG blk;
{
diskreq->io_Length = BLOCKSIZE;
diskreq->io_Data = diskbuffer;
diskreq->io_Command = TD_READ;
diskreq->io_Offset = blk*512;
DoIO(diskreq);
if(diskreq->io_Error != 0){
printf("Error in read.\n\n");
endtree();
}
}
MotorOff()
{
diskreq->io_Length = 0;
diskreq->io_Command = TD_MOTOR;
DoIO(diskreq);
return;
}
endtree()
{
FileList *tmp;
MotorOff(diskreq);
CloseDevice(diskreq);
DeleteStdIO(diskreq);
DeletePort(diskport);
while(Top != NULL){
tmp = Top;
Top = Top->next;
if(free( (char *)tmp ) != 0)
printf("Error in deallocation of memory.\n\n");
}
}